package com.winxuan.channel.export.kfuz;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;

public class CopyPic {

	public static void main(String[] args) throws IOException {
		BufferedReader bufferedReader = new BufferedReader(new FileReader("/home/newad/hidehai-kfuz-images.txt"));
		String string = null;
		String prePicPath = "/home/newwebhome/newxhbs/";
		String destPrePath = "/home/newad/images/";
		int i=0;
		FileOutputStream fos = null;
		while ((string = bufferedReader.readLine()) != null) {
			System.out.println(i++);
			if (!string.equals("")) {
				String[] array = string.split(",");
				String id = array[0];
				String picPath = array[1];
				String filePath = prePicPath + picPath;
				File file = new File(filePath);
				System.out.println(filePath + " : " + file.exists());
				if(file.exists()){
					String destFile = destPrePath +"mid_"+ id + ".jpg";
					InputStream is = new FileInputStream(file);
					fos = new FileOutputStream(destFile);
					byte[] buffer = new byte[1024];
					while (is.read(buffer) != -1) {
						fos.write(buffer);
					}
					is.close();
					fos.close();
				}
			}
			if(i%1000 == 0)
				System.gc();
		}
		bufferedReader.close();
		File file = new File("/home/newad/kfuz-images-new.tar");
		file.deleteOnExit();
		Runtime.getRuntime().exec("tar -cvf /home/newad/hidehai-kfuz.tar /home/newad/images/");			
	}

}
